package com.sunny.ihealth.ui.fragment;


import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.sunny.ihealth.BaseFragment;
import com.sunny.ihealth.R;
import com.sunny.ihealth.ui.adapter.CommonFragmentPagerAdapter;
import com.sunny.ihealth.ui.adapter.FriendAndFansAdapter;


public class TabDateFragment extends BaseFragment {

    private TabLayout tabLayout;
    private ViewPager viewPager;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_tab_date, container, false);
        initViews(view);
        return view;
    }

    @Override
    public void initViews(View v) {
        tabLayout = (TabLayout) v.findViewById(R.id.tableLayout_date);
        viewPager = (ViewPager) v.findViewById(R.id.viewPager_date);


        Fragment[] fragments = new Fragment[2];
        fragments[0] = new FriendFragment();
        fragments[1] = new FriendFragment();

        Bundle bundle1 = new Bundle();
        bundle1.putInt("type", FriendAndFansAdapter.TYPE_FRIEND);
        Bundle bundle2 = new Bundle();
        bundle2.putInt("type", FriendAndFansAdapter.TYPE_FANS);
        fragments[0].setArguments(bundle1);
        fragments[1].setArguments(bundle2);


        String[] titles = new String[]{"关注", "粉丝"};

        CommonFragmentPagerAdapter adapter = new CommonFragmentPagerAdapter(getChildFragmentManager(), fragments, titles);
        viewPager.setAdapter(adapter);
        tabLayout.setupWithViewPager(viewPager);

    }
}
